<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;
class GoodsCreateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return Auth::check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rl=array(
            'name' => 'required',
            'codeno' => 'required|unique:goods',
            'price' => 'numeric',
 
        );
        if(Request::segment(3)){
            $rl['codeno']='required|unique:goods,codeno,'.Request::segment(3);
            
        }
        return $rl;
    }
    public function messages()
    {
        return [
            'name.required'=>'请填写产品名称',
            'codeno.required'=>'请输入产品编号',
            'codeno.unique'=>'产品编号已经存在,请重新填写',
            'price.numeric'=>'产品价格请输入数字',
       
        ];
        
    }
}
